#include <iostream>

using namespace std;

struct LinkNode{
    int val;
    LinkNode* next;
    LinkNode():val(0),next(nullptr){}
    LinkNode(int num):val(num),next(nullptr){}
    LinkNode(int num,LinkNode* n):val(num),next(n){}
};

LinkNode* getLink(LinkNode* head,int num){
    LinkNode* nhead=new LinkNode(-1);
    nhead->next=head;
    LinkNode* cur;
    cur=nhead;
    while(cur->next!=nullptr){
        if(cur->next->val==num){
            LinkNode* tem=cur->next;
            cur->next=tem->next;
            delete tem;
            tem=nullptr;
        }else cur=cur->next;
    }
    head=nhead->next;
    delete nhead;
    nhead=nullptr;
    return head;
}

int main(){
    LinkNode* node1=new LinkNode(1);
    LinkNode* node2=new LinkNode(2);
    LinkNode* node3=new LinkNode(4);
    LinkNode* node4=new LinkNode(4);
    LinkNode* node5=new LinkNode(3);
    node1->next=node2;
    node2->next=node3;
    node3->next=node4;
    node4->next=node5;
    node5->next=nullptr;
    LinkNode* head=new LinkNode();
    head=getLink(node1,4);
    LinkNode* cur=head;
    while(cur!=nullptr){
        cout<<"val= "<<cur->val<<endl;
        cur=cur->next;
    }
    return 0;
}